import { http } from "@/utils/http";
import type { HttpResult } from "@/utils/http/types";

export function getPage(params?: object) {
  return http.request<HttpResult>("get", "/esflow/def/gettable", {
    params: params
  });
}

export function getList(params?: object) {
  return http.request<HttpResult>("get", "/esflow/def/get/list", {
    params: params
  });
}

export function getLatestPage(params?: object) {
  return http.request<HttpResult>("get", "/esflow/def/get/latest/table", {
    params: params
  });
}

export function getLatestList(params?: object) {
  return http.request<HttpResult>("get", "/esflow/def/get/latest/list", {
    params: params
  });
}

export function getLatestByKey(key?: string) {
  return http.request<HttpResult>("get", `/esflow/def/get/latest/${key}`);
}

export function addObj(params?: object) {
  return http.request<HttpResult>("post", "/esflow/def/insert", {
    data: params
  });
}

export function addOrUpdateObj(params?: object) {
  return http.request<HttpResult>("post", "/esflow/def/insertOrUpdate", {
    data: params
  });
}

export function getObj(id?: string) {
  return http.request<HttpResult>("get", `/esflow/def/get/${id}`);
}

export function updateObj(params: any) {
  return http.request<HttpResult>("post", "/esflow/def/update", {
    data: params
  });
}

export function delObj(params: any) {
  return http.request<HttpResult>("post", "/esflow/def/delete", {
    data: params
  });
}

export function delObjs(ids?: string) {
  return http.request<HttpResult>("post", `/esflow/def/delete/${ids}`);
}

/**
 * 根据流程名称获取信息
 *
 * @return AxiosPromise
 */
export function validFlowKey(params: object) {
  return http.request<HttpResult>("get", "/esflow/def/get/valid", {
    params: params
  });
}
